﻿#region copyright
//<copyright>
// Copyright(C) 2012 TrackerRealm Corporation
// This file is part of the open source project - Jazz. http://jazz.codeplex.com
// 
// Jazzfire is open software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License (AGPL) as published by the Free Software Foundation, version 3 of the License.
// 
// Jazzfire is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License (AGPL) for more details.
// 
// You should have received a copy of the GNU General Public License along with Jetfire.  If not, see <http://www.gnu.org/licenses/>.
//
// REMOVAL OF THIS NOTICE IS VIOLATION OF THE COPYRIGHT. 
//</copyright>
#endregion
# region using
using TrackerRealm.Jazz.Client;
using TrackerRealm.Jazz.Client.Custom;
using System;
using System.Windows.Forms;
# endregion

namespace TrackerRealm.Jazz.WindowsForm
{
    /// <summary>
    /// Creator is used to indicate which Roles are allowed to create objects
    /// </summary>
    [Jazz]
    public class Creator : jObject
    {
        # region Constructor
        ClientNexus nexus = null;
        public Creator(ClientNexus nexus) : base(nexus)
        {
            this.nexus = nexus;
        }
        # endregion

        # region Public Methods
        /// <summary>
        /// Create a Role - Can only be done by user with UserAdmin role
        /// </summary>
        /// <param name="name">Name of Role</param>
        /// <returns></returns>
        [UI, GrantRoles("UserAdmin")]
        public jRole Create_Role(string name)
        {
            try
            {
                return jRole.Create(this.nexus, name);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return null;
            }
        }
        /// <summary>
        /// Create a User - Can only be done by user with UserAdmin role
        /// </summary>
        /// <param name="name">Name of User</param>
        /// <returns></returns>
        [UI, GrantRoles("UserAdmin")]
        public jUser Create_User(string name)
        {
            try
            {
                return jUser.Create(this.nexus, name);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return null;
            }
        }
        /// <summary>
        /// Create a To Do Item - Can only be done by user with ToDo role
        /// </summary>
        /// <param name="subject">Subject of To Do Item</param>
        /// <returns></returns>
        [UI, GrantRoles("ToDo")]
        public GroupToDo Create_To_Do_Item(string subject)
        {
            return new GroupToDo(this.nexus, subject);
        }
        # endregion
    }
}